//var url="http://120.26.222.134:8088/equipment/"
//var url="http://192.168.0.195:8083/"
//var url="http://10.37.10.245:8088/mis/"
//var url="http://192.168.0.216:8083/"
var url="http://120.26.222.134:8088/mis/"
//封装的请求，根据返回的code，提示错误信息
	app.factory('pos',function($http,$q,$rootScope,$state) {
	var obj= {};
	//获取用户列表
	obj.list = function(u,o) {
		//o  外部传入的参数
		o = o || {}; //强制让undefined等于空对象
		var q = $q.defer();
		$http({    
			url:url+u,    
            method: "POST", 
            headers: { 'Content-Type': 'application/json;charset=utf-8'},
            data: o,
   }).then(function(e) {     
   	          	q.resolve(e.data.data);  
   	          	  return
		})          
		return q.promise;        
	}   
	return obj;
}) 
	app.factory('post',function($http,$q,$rootScope,$state) {
	var obj= {};
	//获取用户列表
	obj.list = function(u,o) {
		var menu=sessionStorage.getItem("menu")
		//o  外部传入的参数
		o = o || {}; //强制让undefined等于空对象
		var q = $q.defer();
		$http({    
			url:url+u,    
            method: "POST",  
            headers: { 'Content-Type': 'application/x-www-form-urlencoded'},
            data: o,
            transformRequest: function(obj) {  
     var str = [];  
     for(var p in obj){  
       str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));  
     }  
     return str.join("&");  
   }  
   }).then(function(e) {     
// 		q.resolve(e.data);
   	          	q.resolve(e.data.data);     
   	          	     return
		})          
		return q.promise;        
	}   
	return obj;
}) 
app.factory('get',function($http,$q,$rootScope,$state,$cacheFactory) {
	
	var obj= {};

	//获取用户列表
	obj.list = function(u,o) {
		//o  外部传入的参数
		o = o || {}; //强制让undefined等于空对象
		var q = $q.defer();
		$http({    
			url:url+u,    
            method: "GET",
            headers: { 'Content-Type': 'application/x-www-form-urlencoded'},
            params: o,
            transformRequest: function(obj) {  
     var str = [];  
     for(var p in obj){  
       str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));  
     }  
     return str.join("&");  
   }  
   }).then(function(e) {     
// 	q.resolve(e.data.result);
				 if(e.data.code==500){
				 	 q.resolve( e.data); 
				 }else if(e.data.code==402){
				 	window.location.href="index.html#!/login"
				console.log(e)
				 }else{
				 	 q.resolve(e.data.data);  
				 }
		})  
		return q.promise;        
	}   

	return obj;
})
app.factory('put',function($http,$q,$rootScope,$state) {
	var obj= {};
	//获取用户列表
	obj.list = function(u,o) {
		//o  外部传入的参数
		o = o || {}; //强制让undefined等于空对象
		var q = $q.defer();
		$http({    
			url:url+u,    
            method: "PUT", 
            headers: { 'Content-Type': 'application/json'},
            params: o,
            transformRequest: function(obj) {  
     var str = [];  
     for(var p in obj){  
       str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));  
     }  
     return str.join("&");  
   }  
   }).then(function(e) {   
// 	q.resolve(e.data);     
   	if (e.data.code==200) {
   	          q.resolve(e.data);     
				console.info(e)
   	          } else if(e.data.code==403){
// 	          	$rootScope.open("myModalNoPower.html")
   	          	$state.go("error",{code:403})
   	          	     return
   	          }else if(e.data.code==500){
// 	          		$rootScope.open("myModalError.html")
   	          		$state.go("error",{code:500})
   	          	     return
   	          }else if(e.data.code==530){
   	          		$rootScope.open("myModalLoginGq.html")
   	          		window.location.href = 'login.html';
			sessionStorage.clear()
   	          	     return
   	          }
				
		})          
		return q.promise;        
	}   
	return obj;
}) 
app.factory('del',function($http,$q,$rootScope,$state) {
	var obj= {};
	//获取用户列表
	obj.list = function(u,o) {
		//o  外部传入的参数
		o = o || {}; //强制让undefined等于空对象
		var q = $q.defer();
		$http({    
			url:url+u,    
            method: "DELETE",   
            headers: { 'Content-Type': 'application/json'},
            params: o,
           transformRequest: function(obj) {  
	    var str = [];  
	     for(var p in obj){  
	       str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));  
	     }  
	     return str.join("&");
	   }  
   }).then(function(e) {    
// 	q.resolve(e.data);    
   	          q.resolve(e.data.data);   
   	           return
		})          
		return q.promise;        
	}   
	return obj;
}) 

